<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            padding: 0;
            margin: 0;
            box-sizing: border-box;
        }
        .box{
            width: 520px;
            height: 500px;
            background-color: #ccc;
            margin: auto;
            padding: 20px 0 0 20px;
        }
        span {
            display: inline-block;
            width: 100px;
            line-height: 100px;
            background-color: black;
            color: #fff;
            text-align: center;
            margin:0 20px 20px 0;
        }
        p{
            width: 460px;
            height: 100px;
            background-color: #fff;
        }
        /* span:nth-child(4),span:nth-child(8),span:nth-child(12){
            margin-right: 0;
        } */
        
    </style>
</head>

<body>
    <div class="box">
        <span>1</span>
        <span>2</span>
        <span>3</span>
        <span>4</span>
        <span>5</span>
        <span>6</span>
        <span>7</span>
        <span>8</span>
        <span>9</span>
        <span>10</span>
        <span>11</span>
        <span>12</span>
        <p>1</p>
    </div>
</body>
<script>
    var spans=document.querySelectorAll('span')
    var p=document.querySelector('p')
    for (let i = 0; i < spans.length; i++) {
        spans[i].onmousemove=function(){
            spans[i].style.cssText="background-color:red;border:1px solid black;color:#fff"
            p.innerHTML=spans[i].innerHTML
        }
        spans[i].onmouseout=function(){
            spans[i].style.cssText=""
            p.innerHTML=''
        }
    }
</script>
</html> 
